package com.etl.dataflow.scheduler.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.etl.dataflow.common.response.R;
import com.etl.dataflow.scheduler.admin.entity.DataflowDatasource;
import com.etl.dataflow.scheduler.admin.entity.request.PageRequest;
import com.etl.dataflow.scheduler.admin.mapper.DataflowDatasourceMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据源管理服务实现类
 * </p>
 *
 * @author dx
 * @since 2022-04-23
 */
@Service
public class DataflowDatasourceService extends ServiceImpl<DataflowDatasourceMapper, DataflowDatasource>
        implements DefaultService<DataflowDatasource> {

    public R page(PageRequest pageRequest) {
        Page<DataflowDatasource> datasourcePage = super.baseMapper.selectPage(toPage(pageRequest), orLikeAllFields(pageRequest, DataflowDatasource.class, "id"));
        return R.success().put("data", datasourcePage);
    }

    public R search(String keyword) {
        QueryWrapper<DataflowDatasource> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("nickname", "%" + keyword + "%");
        List<DataflowDatasource> datasourceList = super.baseMapper.selectList(queryWrapper);
        return R.success().put("data", datasourceList);
    }
}
